<template>
  <div class="drawer" :class="{ hidden: !visible }">
    <div class="drawer-body" :style="{ width: px2vw(parseFloat(width)) }">
      <slot />
    </div>
    <div class="btn-close" @click="toggle"></div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { px2vw } from '@/utils/responsible'

const { width } = defineProps<{
  width: string
}>()

const visible = ref(true)

function toggle() {
  visible.value = !visible.value
}
</script>

<style lang="scss" scoped>
.drawer {
  z-index: $drawerIndex;
  position: fixed;
  top: $headerHeight + 12px;
  left: 0;
  bottom: 20px;
  // height: 864px;
  padding-left: 20px;
  transition: transform 0.2s ease-in-out;

  .drawer-body {
    height: 100%;
    padding: 16px 20px;
    border: 1px solid rgba(64, 88, 123, 0.75);
    background-color: rgba($color: #032136, $alpha: 0.9);
    color: #fff;
  }

  &.hidden {
    transform: translateX(-100%);
  }

  .btn-close {
    position: absolute;
    width: 18px;
    height: 164px;
    right: -18px;
    top: 50%;
    transform: translateY(-50%);
    background-image: url(../assets/bg_drawer_switch.png);
    background-size: cover;
    background-repeat: no-repeat;
    cursor: pointer;
  }
}
</style>
